<template>
	<div class="system-dicManager-dialog-container">
		<el-dialog :close-on-click-modal="false" :title="state.dialog.title" v-model="state.dialog.isShowDialog"
			width="700px">

			<el-card shadow="hover">
				<el-form ref="editDialogFormRef" :model="state.ruleForm" :rules="rules" size="default" label-width="100px">
					<el-row :gutter="35">



						<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
							<el-form-item label="审核状态" prop="isPass">
								<el-select clearable v-model="state.ruleForm.isPass">
									<el-option value="1" label='拒绝'>
									</el-option>
									<el-option value="2" label='通过'>
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>


						<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"
							v-if="state.ruleForm.isPass == '1'">
							<el-form-item label="原因" prop="reason">
								<el-input v-model="state.ruleForm.reason" placeholder="原因" clearable></el-input>
							</el-form-item>
						</el-col>

						<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
							<el-form-item label="谷歌验证码" prop="gugolCode">
								<el-input v-model="state.ruleForm.gugolCode" placeholder="谷歌验证码" clearable></el-input>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</el-card>

			<template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
				</span>
			</template>
		</el-dialog>

	</div>
</template>

<script setup lang="ts" name="systemDicDialog">
import { ElMessage } from 'element-plus';
import { reactive, ref, watch, defineAsyncComponent } from 'vue';

// 导入接口
import { useFundApi } from '/@/api/fund/index';

const editDialogFormRef = ref();

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);

const rules = {

	isPass: [
		{ required: true, message: "请选择", trigger: "blur" }
	],
	gugolCode: [
		{ required: true, message: "请输入谷歌验证码", trigger: "blur" }
	]

}

const state = reactive({
	row: null as any,
	leveList: [] as any,
	ruleForm: {
		isPass: "",
		reason: "",
		gugolCode: ""
	},
	dialog: {
		isShowDialog: false,
		type: '',
		title: '',
		submitTxt: '',
	},
});


// 打开弹窗
const openDialog = async (type: string, row?: any) => {

	if (type === 'edit') {
		state.row = row;
		state.ruleForm = {
			isPass: "",
			reason: "",
			gugolCode: ""
		}
		state.dialog.title = '提现审核';
		state.dialog.submitTxt = '确 定';
	} else { }
	state.dialog.type = type;
	state.dialog.isShowDialog = true;
};


// 关闭弹窗
const closeDialog = () => {
	state.dialog.isShowDialog = false;
};

// 取消
const onCancel = () => {
	closeDialog();
};
// 提交
const onSubmit = async () => {
	editDialogFormRef.value.validate(async (valid: any) => {
		if (valid) {
			//检查参数列表

			try {
				if (state.dialog.type == 'edit') {
					let vo = {
						id: state.row.id,
						isPass: state.ruleForm.isPass == "2" ? "AUDIT_PASS" : "AUDIT_REFUSE",
						remark: state.ruleForm.reason
					} as any;
					await useFundApi().authWithdraw(vo, state.ruleForm.gugolCode);
				}
				ElMessage.success("操作成功");
				closeDialog(); // 关闭弹窗
				emit('refresh');
			} catch (error: any) {
				ElMessage.error("操作失败请稍后再试");
			}
		} else {
			ElMessage.warning("请检查数据的正确性！");
		}
	})
};




watch(
	() => state.dialog.isShowDialog,
	(newValue) => {
		if (newValue == true) {
		}
	}, { immediate: true }
);




// 暴露变量
defineExpose({
	openDialog,
});
</script>

<style lang="scss">
.el-select {
	width: 100% !important;
}



.system-dicManager-dialog-container {
	.bar_tools {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 10px;
	}

	.el-table__expanded-cell {
		padding: 20px;
	}
}
</style>